<template>
   <lay-container fluid="true" style="padding: 10px">
    <lay-row :space="10">
      <lay-col :md="24">
        <lay-card>
          <lay-form style="margin-top: 20px">
            <lay-row>
              <lay-col :md="6">
                <lay-form-item label="关键字：" label-width="60">
                  <lay-input
                    v-model="qm.key" style="width: 90%" 
                    placeholder="关键字"
                    :allow-clear="true"
                  ></lay-input>
                </lay-form-item>
              </lay-col>
              
              

              <lay-col :md="14">
                <lay-form-item label-width="0">
                  <lay-button type="primary" @click="toSearch">查询</lay-button>
                  <lay-button @click="toReset">重置</lay-button>
                </lay-form-item>
              </lay-col>
            </lay-row>
          </lay-form>
        </lay-card>
      </lay-col>
      <lay-col :md="24">
        <lay-card>
          <lay-table
            :page="page"
            :columns="columns"
            :dataSource="dataSource"
            :default-toolbar="defaultToolbar"
             
            even
            @Change="pageChange"
          > 
          </lay-table>
        </lay-card>
      </lay-col>
    </lay-row>
  </lay-container>

    
</template>

<script lang="ts">
import { ref, watch,reactive,onMounted,h } from 'vue'
import { layer } from '@layui/layer-vue'
import MyHttp from "../../library/MyHttp";  
import MyWin from "../../library/MyWin"; 
import MyPage from "../../library/MyPage"; 
import {MyExcel} from "../../library/MyExcel"; 
import {MySimpleExport,TableColumn} from "../../library/MySimpleExport"; 
import add from "./add.vue";  
import MyData from '../../library/MyData';

import {useUserStore} from "../../store/user";  
import MyAuth from "../../library/MyAuth"; 

export default {
  props:{
       data:String
   },
  
  setup(prop:any, context:any) {
    
    const baseUrl="/htsql";
    const baseQUrl=baseUrl+"/PageRun";
    const pageName="sql运行日志";
  
    const myWin=ref<any>(null);
    const selectedKeys = ref([ ]) 
    const defaultToolbar = ref(false)
    const page = ref(  new MyPage()  ); 
    page.value.limit=20;
    
    const columns = [
      // {
      //   title: '复选',
      //   width: '50px',
      //   type: 'checkbox',
      //   fixed: 'left'
      // },
      {
        title: '序号',
        width: '50px' ,
        key: 'rowNo'
      },
      { key:'crtDt',title: '创建日期', width: '100px', },
{ key:'runSql',title: '执行Sql', width: '100px', },
{ key:'bkData',title: '备份Sql', width: '100px', },
{ key:'rowCount',title: '影响记录数', width: '100px', },
{ key:'mseconds',title: '耗时', width: '100px', },



    ]

    const dataSource = ref([]);

    const rowClick = function (data: any) {}

    const rowDoubleClick = function (data: any) {}

    const pageChange = function ({ current, limit }: any) {
      if(qm.pageSize!=limit)
      {
        qm.pageSize=limit ;
        qm.page=1;
        query(1); 
      }else{
        query(current)
      }
      

    }
    function toSearch() { 
      query(1);
    }
     
    function toReset() {
      qm.key= '';
      qm.dtb='';
      qm.dte=''; 

    }

    const qm=reactive({
      key:"",
      dtb:"",
      dte:"",  
      page: 1,
      pageSize: 20,
      sortFields:"crtDt desc",
      id:prop.data,
      state:""
    }); 
    const query=async (pageIndex:number) =>{
      if(pageIndex){
        page.value.current=pageIndex;
        qm.page=pageIndex;
      }
      var r=await new MyHttp().page(baseQUrl,qm,
        { 
        },
        columns
      );        
      dataSource.value=r.data.records;          
      page.value.total=r.data.totalRow;
       
    }
     
    const sortChange = (key: any, sort: number) => {
      qm.sortFields=`${key} ${sort}`;
      query(0);
    }
    const tableExport=async()=>{
     
      var cols=columns as Array<TableColumn>;
      new MySimpleExport().exportExcel(
        {
          qm,
          url:baseQUrl,
          name:pageName,
          columns:cols,
          lx:"page"
        }
        );
    }
    
    
    onMounted(() =>{  
      myWin.value=new MyWin();
      query(1);
       
    });
 
    return {
      columns,
      dataSource,
      selectedKeys, 
      defaultToolbar,
      page,
      rowClick,
      rowDoubleClick,
      pageChange,
      toReset,
      toSearch,
       

      qm,
      query,
      
      sortChange,
      tableExport,
    
      myWin,
        
    }
  }
}
</script>
